
var TaskSelector = new Object()

TaskSelector.createView = function() {

	var model = new Object();
	model.getButtonOnClick = function() {
		var dialog = TaskSelector.createTaskTreeDialog();
		dialog.open();
	}

	var selector = WindSelector.createView(model);
	return selector;
}

TaskSelector.createTaskTreeDialog = function() {
	var dialog = WindDialog.createView();
	dialog.setId("taskSelectorDialog");
	dialog.setTitle("Select a task");
	
	{
		var button = WindDialog.createToolbarButtonView();
		button.setText("Cancel");
		button.onClick = function() {
			dialog.close();
		}
		dialog.getToolbar().addView(button);
	}
	
	{
		var tasks = WindData.execute("getTasks");
		var treeModel = TaskTree.createModel(tasks);
	
		treeModel.onNodeDblClick = function(path) {
			var taskDTO = TaskTree.searchTask(tasks, path);
			dialog.close();
		}

		var tree = TaskTree.createView(treeModel);
		tree.setId("taskSelectorTaskTree");
		
		dialog.getBody().addView(tree);
	}
	
	return dialog;
}